package com.zmx.patients.view.activity;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.zmx.patients.BaseActivity;
import com.zmx.patients.R;
import com.zmx.patients.fragment.blood_pressure.BloodPressureChatFragment;
import com.zmx.patients.fragment.blood_pressure.BloodPressureListFragment;
import com.zmx.patients.fragment.body_temperature.BodyChatFragment;
import com.zmx.patients.fragment.body_temperature.BodyListFragment;
import com.zmx.patients.fragment.pulse_condition.PulseConditionChatFragment;
import com.zmx.patients.fragment.pulse_condition.PulseConditionListFragment;

import java.util.ArrayList;
import java.util.List;

public class BodyTemperatureActivity extends BaseActivity {


    static final int NUM_ITEMS = 2;
    private List<Fragment> fragmentList = new ArrayList<Fragment>();
    private String[] strings = new String[]{"列表分析","图表分析"};
    private String logo;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_body_temperature;
    }

    @Override
    protected void initViews() {

        setToolbar(R.id.tool_bar);

        logo = this.getIntent().getStringExtra("logo");

        if (logo.equals("a")){

            BodyListFragment aof = new BodyListFragment();
            BodyChatFragment ftf = new BodyChatFragment();
            fragmentList.add(aof);
            fragmentList.add(ftf);

        }else if (logo.equals("b")){

            PulseConditionListFragment pcf = new PulseConditionListFragment();
            PulseConditionChatFragment pccf = new PulseConditionChatFragment();
            fragmentList.add(pcf);
            fragmentList.add(pccf);

        }else if (logo.equals("d")){

            BloodPressureListFragment bplf = new BloodPressureListFragment();
            BloodPressureChatFragment bpcf = new BloodPressureChatFragment();
            fragmentList.add(bplf);
            fragmentList.add(bpcf);

        }


        TabLayout tab_layout = findViewById(R.id.tab_layout);
        ViewPager viewPager = findViewById(R.id.viewPager);
        BodyTemperatureActivity.MyAdapter fragmentAdater = new BodyTemperatureActivity.MyAdapter(getSupportFragmentManager());
        viewPager.setAdapter(fragmentAdater);
        tab_layout.setupWithViewPager(viewPager);

    }


    public class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return NUM_ITEMS;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return strings[position];
        }
    }


}
